--- /dev/null
+use glib;
+use std::fmt::Display;
+use std::fmt::Formatter;
+use std::fmt::Error;
+
+/// Details of an object in an OSTree repo. It contains information about if
+/// the object is "loose", and contains a list of pack file checksums in which
+/// this object appears.
+#[derive(Debug)]
+pub struct ObjectDetails {
+ loose: bool,
+ object_appearances: Vec<String>,
+}
+
+impl ObjectDetails {
+ /// Create a new `ObjectDetails` from a serialized representation.
+ pub fn new_from_variant(variant: glib::Variant) -> Option<ObjectDetails> {
+ let deserialize = variant.get::<(bool, Vec<String>)>()?;
+ Some(ObjectDetails {
+ loose: deserialize.0,
+ object_appearances: deserialize.1,
+ })
+ }
+
+ /// is object available "loose"
+ pub fn is_loose(&self) -> bool {
+ self.loose
+ }
+
+ /// Provide list of pack file checksums in which the object appears
+ pub fn appearances(&self) -> &Vec<String> {
+ &self.object_appearances
+ }
+
+ /// Format this `ObjectDetails` as a string.
+ fn to_string(&self) -> String {
+ format!("Object is {} loose and appears in {} checksums",
+ if self.loose {"available"} else {"not available"},
+ self.object_appearances.len() )
+ }
+}
+
+impl Display for ObjectDetails{
+ fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
+ write!(f, "{}", self.to_string())
+ }
+}
+
#[cfg(any(feature = "v2016_4", feature = "dox"))]
use crate::RepoListRefsExtFlags;
-use crate::{Checksum, ObjectName, ObjectType, Repo, RepoTransactionStats};
+use crate::{Checksum, ObjectName, ObjectDetails, ObjectType, Repo, RepoTransactionStats};
use ffi;
use ffi::OstreeRepoListObjectsFlags;
use glib::ffi as glib_sys;
) {
let key: glib::Variant = from_glib_none(key as *const glib_sys::GVariant);
let value: glib::Variant = from_glib_none(value as *const glib_sys::GVariant);
- if let Some(insert) = value.get::<(bool, Vec<String>)>() {
- let set: &mut HashMap<ObjectName, (bool, Vec<String>)> = &mut *(hash_set as *mut HashMap<ObjectName, (bool, Vec<String>)>);
- set.insert(ObjectName::new_from_variant(key), insert);
+ let set: &mut HashMap<ObjectName, ObjectDetails> = &mut *(hash_set as *mut HashMap<ObjectName, ObjectDetails>);
+ if let Some(details) = ObjectDetails::new_from_variant(value) {
+ set.insert(ObjectName::new_from_variant(key), details);
}
}
set
}
-unsafe fn from_glib_container_variant_map(ptr: *mut glib_sys::GHashTable) -> HashMap<ObjectName, (bool, Vec<String>)> {
+unsafe fn from_glib_container_variant_map(ptr: *mut glib_sys::GHashTable) -> HashMap<ObjectName, ObjectDetails> {
let mut set = HashMap::new();
glib_sys::g_hash_table_foreach(
ptr,
Some(read_variant_object_map),
- &mut set as *mut HashMap<ObjectName, (bool, Vec<String>)> as *mut _,
+ &mut set as *mut HashMap<ObjectName, ObjectDetails> as *mut _,
);
glib_sys::g_hash_table_unref(ptr);
set
&self,
flags: OstreeRepoListObjectsFlags,
cancellable: Option<&P>,
- ) -> Result<HashMap<ObjectName, (bool, Vec<String>)>, Error> {
+ ) -> Result<HashMap<ObjectName, ObjectDetails>, Error> {
unsafe {
let mut error = ptr::null_mut();
let mut hashtable = ptr::null_mut();